<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>舞林大会活动明细</title>





<script type="text/javascript">
	var url;
	var href=window.location.href;
	var arrhref=href.split("?activityId=");
	//活动主键
	var activityId = arrhref[1].split('#')[0];
	
	if(arrhref!=null){
		//activityId=arrhref[1];
	}
	
	$(function() {
		//查询
		query(activityId);
	});

	
	//查询
	function query(activityId) {
		$("#table").datagrid({
			title:"活动明细",
			url : "<%=basePath%>dance/getActivityDetail",
			 // pagination:true,//分页控件  
			queryParams : {
				activityId : activityId,
				code : $.trim($('#code_s').val()),
				name : $.trim($('#name_s').val())
			}

		});
		//getPage();
	}

	//清空查询条件
	function reset() {
		$("input").val("");
	}

	
	//新增活动
	function addActivity() {
		
		//设置地址
		url = "<%=basePath%>dance/addActivityDetail";
		//打开对话框
		$('#dlg').dialog('open').dialog('setTitle', '新增活动明细');
		//清空
		$('#fm').form('clear');
		
	}

	
	//编辑订单
	function editActivity() {
		//选中的行
		var row = $('#table').datagrid('getSelected');
		if (row) {
			//设置地址
			url = "<%=basePath%>dance/updateActivityDetail";
			$('#dlg').dialog('open').dialog('setTitle', '编辑活动明细');
			$('#fm').form('load', row); 

		}else{
			$.messager.alert({
				title : 'Failed!',
				msg : '请先选中一行!',
				//居中
				style : {
					right : '',
					bottom : ''
				}
			});
		}
	}
	
	//获得参数
	function getParams(){
		//主键
		var id=$.trim($("#id").val());
		//编码
		var code =$.trim($("#code").val()); 
		//名称
		var name =$.trim($("#name").val());
		//开始时间
		var beginDate = $.trim($("#beginDate").datebox('getValue'));
		beginDate = dateFormat(beginDate);
		//结束时间
		var endDate = $.trim($("#endDate").datebox('getValue'));
		endDate = dateFormat(endDate);
		//期数
		var phase = $.trim($("#phase").val()); 
		//信息
		var information = $.trim($("#information").val()); 
		//备注
		var remark = $.trim($("#remark").val()); 
		
		return{
			"id":id,"activityId":activityId,"code":code,"name":name,"beginDate":beginDate,"endDate":endDate,"phase":phase,"information":information,"remark":remark
		}
	}
	
	
	
	//保存活动明细
	function saveActivity() {
		if($.trim($("#phase").val())==null||$.trim($("#phase").val())==''){
			alert("活动明细的期数不能为空！");
			return;
			
		}
		
		$.ajax({
			type:"POST",
			data:getParams(),
			//根据事先设置的地址决定调用哪个方法
			url : url,
			success : function(result) {
				if (result.success) {
					$.messager.alert({
						title : 'Success!',
						msg : '成功!',
					});

					$('#dlg').dialog('close');
					//重新加载表格
					reload();

				} else {
					$.messager.alert({
						title : 'Failed!',
						msg : '失败!',
					});

				}

			},
			error : function(result) {
				$.messager.alert({
					title : 'Failed!',
					msg : '添加失败!',
				});
			}

		});

	}

	//删除活动明细
	function removeActivity() {
		
		
		//勾选中的行
		var rows = $("#table").datagrid("getChecked");
		var ids = new Array();
		for (var i = 0; i < rows.length; i++) {
			ids.push(rows[i].id);
		}
		
		//如果选中了
		if (rows.length>0) {
			$.messager.confirm('Confirm', '确定要删除活动?', function(r) {
				if (r) {
					
					$.ajax({
						type:"POST",
						//传数组时需要设置
						traditional:true,
						data:{
							"ids":ids
						},
						url : "<%=basePath%>dance/removeActivityDetail",
						success:function(result) {
						if (result.success) {
							$.messager.alert({
								title : 'Success',
								msg : '删除成功!',
								//居中
								style : {
									right : '',
									//top:document.body.scrollTop+document.documentElement.scrollTop,
									//top:'',
									bottom : ''
								}
							});
							//重新加载表格
							reload();
						}
					}
					});
				}
			});

		}else{
			$.messager.alert({
				title : 'Failed!',
				msg : '请先勾选要删除的行!',
				//居中
				style : {
					right : '',
					bottom : ''
				}
			});
		}
	}


	//重新加载表格
	function reload(){
		$('#table').datagrid('reload');
	}
	
	
	
	
	
</script>
</head>
<body>
	<tr>
		<th>活动编码</th>
		<td><input type="text" id="code_s" name="code_s" /></td>
		<th>活动名称</th>
		<td><input type="text" id="name_s" name="name_s" /></td>
	</tr>
	<a href="javascript:void(0);" class="easyui-linkbutton" iconCls='icon-search' onclick="query();">查询</a>
	<a href="javascript:void(0);" class="easyui-linkbutton" iconCls='icon-remove' onclick="reset();">重置</a>
	<table id="table" class="easyui-datagrid" fitColumns="true" toolbar="#toolbar" singleSelect="true" checkOnSelect="false" selectOnCheck="false" pagination="true">
		<thead>
			<tr>
				<th field="id" checkbox="true">ID</th>
				<th field="code" width="80">编码</th>
				<th field="name" width="80"  >名称</th>
				<th field="beginDate" width="80"  >开始日期</th>
				<th field="endDate" width="80">结束日期</th>
				<th field="phase" width="80">期数</th>
				<th field="information" width="80">信息</th>
				<th field="creator" width="80">创建人</th>
				<th field="createTime" width="100" formatter="dateFormat"  >创建时间</th>
				<th field="modifier" width="80">修改人</th>
				<th field="updateTime" width="100" formatter="dateFormat" >修改时间</th>
				<th field="remark" width="80">备注</th>
				
			</tr>
		</thead>
	</table>

	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addActivity()">新增</a> <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editActivity()">编辑</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeActivity()">删除</a>
	</div>



	<!-- 对话框 -->
	<div id="dlg" class="easyui-dialog" style="width: 400px, height:280px; padding: 10px 20px" closed="true" buttons="#dlg-buttons">
		<!-- <div class="ftitle">活动</div> -->
		<form id="fm" method="post">
			<table>
				<div style="display:none">
					<label>ID</label>
					<input id="id" name="id" class="easyui-validatebox" required="true">
				
				</div>	
				<tr>
					<td><label>编码</label></td>
					<td><input id="code" name="code" class="easyui-validatebox" required="true"></td>
				</tr>
				
				<tr>
					<td><label>名称</label></td>
					<td><input id="name" name="name" class="easyui-validatebox" required="true"></td>
				</tr>

				<tr>
					<td><label>开始日期</label></td>
					<td><input class="easyui-datebox" id="beginDate" name="beginDate" class="easyui-validatebox" formatter="formatter(this)" required="true"></td>
				</tr>

				<tr>
					<td><label>结束日期</label></td>
					<td><input class="easyui-datebox" id="endDate" name="endDate" class="easyui-validatebox" required="true"></td>
				</tr>

				<tr>
					<td><label>期数</label></td>
					<td><input id="phase" name="phase" class="easyui-numberbox" class="easyui-validatebox" required="true"></td>
				</tr>

				<tr>
					<td><label>信息</label></td>
					<td><input id="information" name="information" class="easyui-validatebox" required="true"></td>
				</tr>

				<tr>
					<td><label>备注</label></td>
					<td><input id="remark" name="remark"  class="easyui-validatebox" multiline="true"></td>
				</tr>

			</table>
		</form>
	</div>


	<!-- 按钮 -->
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveActivity();">保存</a> <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
	</div>

</body>
</html>